package com.wangshuo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wangshuo.config.Result;
import com.wangshuo.domain.SysRole;
import com.wangshuo.mapper.SysRoleMapper;
import com.wangshuo.model.system.SysMenu;
import com.wangshuo.service.SysMenuService;
import com.wangshuo.service.SysRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name="测试")
@RequestMapping("/test")
public class TestController {
    @Resource
    private SysMenuService service;
    @Autowired
    private SysRoleMapper sysRoleMapper;
    @Resource
    private SysRoleService sysRoleService;

    @GetMapping("/hello")
    public Result hello() {
        List<SysRole> users = sysRoleMapper.selectList(null);
        for (SysRole sysRole : users) {
            System.out.println(sysRole);

        }
        return Result.ok(users);
    }
    @GetMapping("/insert")
    public Result insert(){
        SysRole sysRole=new SysRole();
        sysRole.setRoleName("角色管理");
        sysRole.setRoleCode("123");
        sysRoleService.saveOrUpdate(sysRole);
        return Result.ok("123");
    }
    @GetMapping("/rolepage")
    @Operation(summary = "角色分页")
    public Result rolelist(@RequestParam long page,@RequestParam long limit,@RequestParam String keyword){
        IPage<SysRole> page1=new Page<>(page,limit);
        IPage<SysRole> list=sysRoleService.getlist(page1,keyword);
        return Result.ok(list);
    }
    @PostMapping("/addorupdaterole")
    @Operation(summary = "新增修改角色")
    public Result addrole(@RequestBody SysRole sysRole){
        sysRoleService.saveOrUpdate(sysRole);
        return Result.ok("成功");

    }
    @GetMapping("/delete")
    @Operation(summary = "删除角色")
    public Result delete(@RequestParam long id){
        sysRoleService.removeById(id);
        return Result.ok("成功");
    }
    @PostMapping("/BatchRemove")
    @Operation(summary = "批量删除角色")
    public Result BatchRemove(@RequestBody List<Long> idlist){
        sysRoleService.removeByIds(idlist);
        return Result.ok("成功");
    }


}
